package com.bw.producer.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

@Configuration
public class ProductThreadPoolConfig {

    @Bean(name = "productThreadPool")
    public ThreadPoolExecutor productThreadPool(ItemThreadPoolProperties itemThreadPoolProperties) {
        return new ThreadPoolExecutor(
                itemThreadPoolProperties.getCorePoolSize(),
                itemThreadPoolProperties.getMaximumPoolSize(),
                itemThreadPoolProperties.getKeepAliveSeconds(),
                TimeUnit.MINUTES,
                new LinkedBlockingDeque<>(itemThreadPoolProperties.getQueueLength()),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
